package com.wei.czz.framework.store.manager;

import com.wei.czz.common.constant.RedisConstant;
import com.wei.czz.common.dto.common.GroupValue;
import com.wei.czz.common.dto.store.StoreAccountViewDto;
import com.wei.czz.common.dto.store.StoreBossDto;
import com.wei.czz.common.dto.store.StoreViewDto;
import com.wei.czz.common.dto.store.audit.*;
import com.wei.czz.common.enums.CommonEnum;
import com.wei.czz.common.enums.common.multiDIct.MultiDictEnum;
import com.wei.czz.common.enums.ResultEnum;
import com.wei.czz.common.enums.store.StoreStatusEnum;
import com.wei.czz.common.enums.store.StoreSubmitTypeEnum;
import com.wei.czz.common.exception.CzzException;
import com.wei.czz.common.po.UserPo;
import com.wei.czz.common.utils.SecurityUtils;
import com.wei.czz.common.vo.store.audit.AuditSaveVo;
import com.wei.czz.framework.common.service.MultiDictService;
import com.wei.czz.framework.common.service.RegionCodeService;
import com.wei.czz.framework.store.entity.AuditStoreEntity;
import com.wei.czz.framework.store.entity.StoreAccountEntity;
import com.wei.czz.framework.store.entity.StoreBossEntity;
import com.wei.czz.framework.store.entity.StoreEntity;
import com.wei.czz.framework.store.service.*;
import lombok.AllArgsConstructor;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-12-13 15:22:01
 * className: AuditManager
 * version: 1.0
 * description:
 */
@Component
@AllArgsConstructor
public class AuditManager {

    private static final Logger log = LoggerFactory.getLogger(AuditManager.class);

    private final StoreService storeService;

    private final StoreAccountService storeAccountService;

    private final StoreBossService storeBossService;

    private final AuditStoreService auditStoreService;

    private final AssignStoreService assignStoreService;

    private final RegionCodeService regionCodeService;

    private final MultiDictService multiDictService;

    private final RedissonClient redissonClient;

    @Transactional
    public void saveAuditStore(AuditSaveVo auditSaveVo) {
        // 获取操作用户
        UserPo userPo = SecurityUtils.getUser();
        Date date = new Date();

        String lockKey = RedisConstant.LOCK_STORE_KEY + auditSaveVo.getStoreId();
        RLock lock = redissonClient.getLock(lockKey);
        boolean bool = lock.tryLock();
        log.info("保存商店审核，尝试加锁完成。lockKey={} bool={}", lockKey, bool);
        if (!bool) {
            throw new CzzException(ResultEnum.REFRESH.getCode(), "您审核的商店正在被操作中，审核失败");
        }

        try {
            /*
                获取商店
             */
            StoreEntity store = storeService.getStore(auditSaveVo.getStoreId());
            log.info("商店审核之商店状态：status={} deleteStatus={}", StoreStatusEnum.getName(store.getStatus()),
                    CommonEnum.getName(store.getDeleteStatus()));
            if (CommonEnum.ONE.getValue().equals(store.getDeleteStatus())) {
                log.info("商店已经被删除");
                throw new CzzException(ResultEnum.REFRESH.getCode(), "用户已经删除商店，审核操作中止");
            }
            if (StoreStatusEnum.SAVE.getValue().equals(store.getStatus())) {
                log.info("用户已经主动撤销提交商店审核");
                throw new CzzException(ResultEnum.REFRESH.getCode(), "用户已经主动撤销商店审核，审核操作中止");
            }
            if (StoreStatusEnum.FINISH.getValue().equals(store.getStatus())) {
                log.info("商店已经审核通过");
                throw new CzzException(ResultEnum.REFRESH.getCode(), "商店已经审核通过，审核操作中止");
            }

            /*
                保存审核记录
             */
            auditStoreService.saveAuditStore(auditSaveVo);

            /*
                变更商店状态
             */
            StoreEntity updateStore = new StoreEntity();
            updateStore.setId(auditSaveVo.getStoreId())
                    .setStatus(StoreStatusEnum.FINISH.getValue())
                    .setUpdateTime(date)
                    .setUpdateUser(userPo.getUsername())
                    .setUpdateUserId(userPo.getUserId());
            if (CommonEnum.ONE.getValue().equals(auditSaveVo.getStatus())) {
                /*
                    审核拒绝
                 */
                if (StoreStatusEnum.SUBMIT.getValue().equals(store.getStatus())) {
                    updateStore.setStatus(StoreStatusEnum.AUDIT_RETURN.getValue());
                }
                if (StoreStatusEnum.MODIFY.getValue().equals(store.getStatus())) {
                    updateStore.setStatus(StoreStatusEnum.MODIFY_RETURN.getValue());
                }
            }
            storeService.updateStore(updateStore);

            /*
                删除商店审核分单记录
             */
            List<Integer> submitTypeList = new ArrayList<>();
            if (StoreStatusEnum.SUBMIT.getValue().equals(store.getStatus())) {
                submitTypeList.add(StoreSubmitTypeEnum.SUBMIT_STORE.getValue());
            }
            if (StoreStatusEnum.MODIFY.getValue().equals(store.getStatus())) {
                submitTypeList.add(StoreSubmitTypeEnum.STORE_MODIFY.getValue());
            }
            assignStoreService.batchDeleteAssignStore(Collections.singletonList(auditSaveVo.getStoreId()),
                    submitTypeList);
        } finally {
            if (lock.isLocked() && lock.isHeldByCurrentThread()) {
                lock.unlock();
            }
        }
    }

    @Transactional
    public void saveAuditAccount(AuditSaveVo auditSaveVo) {
        // 获取操作用户
        UserPo userPo = SecurityUtils.getUser();
        Date date = new Date();

        String lockKey = RedisConstant.LOCK_STORE_KEY + auditSaveVo.getStoreId();
        RLock lock = redissonClient.getLock(lockKey);
        boolean bool = lock.tryLock();
        log.info("保存商店账户审核，尝试加锁完成。lockKey={} bool={}", lockKey, bool);
        if (!bool) {
            throw new CzzException(ResultEnum.REFRESH.getCode(), "您审核的商店账户正在被操作中，审核失败");
        }
        try {
            /*
                获取商店账户
             */
            StoreAccountEntity storeAccount = storeAccountService.getStoreAccount(auditSaveVo.getAccountId());
            log.info("商店账户审核之账户审核状态：auditStatus={}", storeAccount.getAuditStatus());
            if (!CommonEnum.ZERO.getValue().equals(storeAccount.getAuditStatus())) {
                log.info("商店账户已经被审核");
                throw new CzzException(ResultEnum.REFRESH.getCode(), "商店账户已经被审核，审核操作中止");
            }

            /*
                保存审核记录
             */
            auditStoreService.saveAuditStore(auditSaveVo);

            /*
                变更商店账户状态
             */
            StoreAccountEntity updateStoreAccount = new StoreAccountEntity();
            updateStoreAccount.setId(auditSaveVo.getAccountId())
                    .setAuditStatus(CommonEnum.ONE.getValue())
                    .setUpdateTime(date)
                    .setUpdateUser(userPo.getUsername())
                    .setUpdateUserId(userPo.getUserId());
            if (CommonEnum.ONE.getValue().equals(auditSaveVo.getStatus())) {
                /*
                    审核拒绝
                 */
                updateStoreAccount.setAuditStatus(CommonEnum.TWO.getValue());
            }
            storeAccountService.updateStoreAccount(updateStoreAccount);

            /*
                删除商店审核分单记录
             */
            List<Integer> submitTypeList = Arrays.asList(StoreSubmitTypeEnum.ADD_STORE_ACCOUNT.getValue(),
                    StoreSubmitTypeEnum.STORE_ACCOUNT_MODIFY.getValue());
            assignStoreService.batchDeleteAssignStore(Collections.singletonList(auditSaveVo.getStoreId()),
                    submitTypeList);

        } finally {
            if (lock.isLocked() && lock.isHeldByCurrentThread()) {
                lock.unlock();
            }
        }
    }

    @Transactional
    public void saveAuditBoss(AuditSaveVo auditSaveVo) {
        // 获取操作用户
        UserPo userPo = SecurityUtils.getUser();
        Date date = new Date();

        String lockKey = RedisConstant.LOCK_STORE_KEY + auditSaveVo.getStoreId();
        RLock lock = redissonClient.getLock(lockKey);
        boolean bool = lock.tryLock();
        log.info("保存商店老板审核，尝试加锁完成。lockKey={} bool={}", lockKey, bool);
        if (!bool) {
            throw new CzzException(ResultEnum.REFRESH.getCode(), "您审核的商店老板正在被操作中，审核失败");
        }
        try {
            /*
                获取商店老板
             */
            StoreBossEntity storeBoss = storeBossService.getStoreBoss(auditSaveVo.getBossId());
            log.info("商店老板审核之老板审核状态：auditStatus={}", storeBoss.getAuditStatus());
            if (!CommonEnum.ZERO.getValue().equals(storeBoss.getAuditStatus())) {
                log.info("商店老板已经被审核");
                throw new CzzException(ResultEnum.REFRESH.getCode(), "商店老板已经被审核，审核操作中止");
            }

            /*
                保存审核记录
             */
            auditStoreService.saveAuditStore(auditSaveVo);

            /*
                变更商店老板状态
             */
            StoreBossEntity updateStoreBoss = new StoreBossEntity();
            updateStoreBoss.setId(auditSaveVo.getBossId())
                    .setAuditStatus(CommonEnum.ONE.getValue())
                    .setUpdateTime(date)
                    .setUpdateUser(userPo.getUsername())
                    .setUpdateUserId(userPo.getUserId());
            if (CommonEnum.ONE.getValue().equals(auditSaveVo.getStatus())) {
                /*
                    审核拒绝
                 */
                updateStoreBoss.setAuditStatus(CommonEnum.TWO.getValue());
            }
            storeBossService.updateStoreBoss(updateStoreBoss);

            /*
                删除商店审核分单记录
             */
            List<Integer> submitTypeList = Arrays.asList(StoreSubmitTypeEnum.ADD_STORE_BOSS.getValue(),
                    StoreSubmitTypeEnum.STORE_BOSS_MODIFY.getValue());
            assignStoreService.batchDeleteAssignStore(Collections.singletonList(auditSaveVo.getStoreId()),
                    submitTypeList);

        } finally {
            if (lock.isLocked() && lock.isHeldByCurrentThread()) {
                lock.unlock();
            }
        }
    }

    public StoreAuditDetailDto getStoreLastFinishDetail(Long businessId) {

        // 地区码code集合
        Set<Integer> regionCodeSet = new HashSet<>();

        /*
            获取商店基础数据
         */
        StoreEntity finishStore = storeService.getLastFinishStore(businessId);
        if (Objects.isNull(finishStore)) {
            log.info("商店最新审核通过数据为空。businessId={}", businessId);
            throw new CzzException(ResultEnum.REQUEST_FAIL.getCode(), "商店审核通过数据不存在");
        }
        StoreViewDto storeViewDto = StoreViewDto.map(finishStore);

        /*
            获取商店账户数据
         */
        StoreAccountEntity preStoreAccount = storeAccountService.getStoreDefaultAccount(finishStore.getId());

        StoreAccountViewDto storeAccountViewDto = StoreAccountViewDto.map(preStoreAccount);

        /*
            获取商店老板数据
         */
        StoreBossEntity preStoreBoss = storeBossService.getStoreDefaultBoss(finishStore.getId());

        StoreBossDto storeBossDto = StoreBossDto.map(preStoreBoss);

        // 收集地区码
        regionCodeSet.add(finishStore.getAddressProvince());
        regionCodeSet.add(finishStore.getAddressCity());
        regionCodeSet.add(finishStore.getAddressDistrict());
        regionCodeSet.add(finishStore.getAddressStreet());
        regionCodeSet.add(preStoreAccount.getBankCity());
        /*
            获取地区名称
         */
        Map<Integer, String> regionNameMap = regionCodeService.batchGetName(regionCodeSet);


        storeViewDto.setAddressProvinceName(regionNameMap.get(storeViewDto.getAddressProvince()))
                .setAddressCityName(regionNameMap.get(storeViewDto.getAddressCity()))
                .setAddressDistrictName(regionNameMap.get(storeViewDto.getAddressDistrict()))
                .setAddressStreetName(regionNameMap.get(storeViewDto.getAddressStreet()));
        storeAccountViewDto.setBankCityName(regionNameMap.get(storeAccountViewDto.getBankCity()));

        StoreAuditDetailDto storeLastFinishDetailDto = new StoreAuditDetailDto();
        storeLastFinishDetailDto.setStoreDto(storeViewDto)
                .setStoreAccountDto(storeAccountViewDto)
                .setStoreBossDto(storeBossDto);
        return storeLastFinishDetailDto;
    }

    public StoreAuditDetailDto getAuditStoreDetail(Long id, Integer contrastStatus) {

        // 地区码code集合
        Set<Integer> regionCodeSet = new HashSet<>();
        // 商店分类集合
        Set<String> storeClassSet = new HashSet<>();


        /*
            获取商店基础数据
         */
        StoreEntity store = storeService.getStore(id);
        log.info("获取商店审核数据之商店状态：status={} deleteStatus={}", StoreStatusEnum.getName(store.getStatus()),
                CommonEnum.getName(store.getDeleteStatus()));
        if (CommonEnum.ONE.getValue().equals(store.getDeleteStatus())) {
            log.info("商店已经被删除");
            throw new CzzException(ResultEnum.REFRESH.getCode(), "用户已经删除商店，审核操作中止");
        }
        if (CommonEnum.ZERO.getValue().equals(contrastStatus)) {
            if (StoreStatusEnum.SAVE.getValue().equals(store.getStatus())) {
                log.info("用户已经主动撤销提交商店审核");
                throw new CzzException(ResultEnum.REFRESH.getCode(), "用户已经主动撤销商店审核，审核操作中止");
            }
            if (StoreStatusEnum.FINISH.getValue().equals(store.getStatus())) {
                log.info("用户已经主动撤销修改商店审核");
                throw new CzzException(ResultEnum.REFRESH.getCode(), "用户已经主动撤销商店审核，审核操作中止");
            }
        }

        regionCodeSet.add(store.getAddressProvince());
        regionCodeSet.add(store.getAddressCity());
        regionCodeSet.add(store.getAddressDistrict());
        regionCodeSet.add(store.getAddressStreet());

        storeClassSet.add(store.getMainClass().toString());
        storeClassSet.add(store.getSubClass().toString());

        /*
            获取上一次审核通过的商店基础数据
            1、contrastStatus==0
            2、商店状态为‘修改’
         */
        StoreViewDto preStore = null;
        StoreEntity finishStore = null;
        if (CommonEnum.ZERO.getValue().equals(contrastStatus)
                && StoreStatusEnum.MODIFY.getValue().equals(store.getStatus())) {
            finishStore = storeService.getLastFinishStore(store.getBusinessId());
            if (Objects.nonNull(finishStore)) {
                preStore = StoreViewDto.map(finishStore);

                regionCodeSet.add(finishStore.getAddressProvince());
                regionCodeSet.add(finishStore.getAddressCity());
                regionCodeSet.add(finishStore.getAddressDistrict());
                regionCodeSet.add(finishStore.getAddressStreet());

                storeClassSet.add(finishStore.getMainClass().toString());
                storeClassSet.add(finishStore.getSubClass().toString());
            }
        }

        /*
            获取商店提交审核记录
            1、contrastStatus==0
         */
        List<HistorySubmitDto> historySubmitDtoList = Collections.emptyList();
        if (CommonEnum.ZERO.getValue().equals(contrastStatus)) {
            List<StoreEntity> historySubmitList = storeService.getHistorySubmitList(store.getBusinessId(),
                    store.getStatus());
            historySubmitDtoList = historySubmitList.stream()
                    .map(historyStore -> {
                        HistorySubmitDto historySubmitDto = new HistorySubmitDto();
                        historySubmitDto.setStoreId(historyStore.getId().toString())
                                .setSubmitTime(historyStore.getCreateTime())
                                .setIsCurrent(id.equals(historyStore.getId()));
                        return historySubmitDto;
                    })
                    .collect(Collectors.toList());
        }

        /*
            获取商店账户数据
         */
        StoreAccountEntity storeAccount = storeAccountService.getStoreDefaultAccount(id);
        regionCodeSet.add(storeAccount.getBankCity());

        /*
            获取上一次审核通过的商店的商店账户
         */
        StoreAccountViewDto preStoreAccountDto = null;
        if (Objects.nonNull(finishStore)) {
            StoreAccountEntity preStoreAccount = storeAccountService.getStoreDefaultAccount(finishStore.getId());
            // 映射
            preStoreAccountDto = StoreAccountViewDto.map(preStoreAccount);

            regionCodeSet.add(preStoreAccount.getBankCity());

        }

        /*
            获取商店老板数据
         */
        StoreBossEntity storeBoss = storeBossService.getStoreDefaultBoss(id);

        /*
            获取上一次审核通过的商店的商店老板
         */
        StoreBossDto preStoreBossDto = null;
        if (Objects.nonNull(finishStore)) {
            StoreBossEntity preStoreBoss = storeBossService.getStoreDefaultBoss(finishStore.getId());
            // 映射
            preStoreBossDto = StoreBossDto.map(preStoreBoss);
        }

        /*
            获取商店审核记录
            1、contrastStatus==0
         */
        List<GroupValue<AuditStoreDto>> auditGroupList = Collections.emptyList();
        if (CommonEnum.ZERO.getValue().equals(contrastStatus)) {
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

            List<AuditStoreEntity> auditStoreList = auditStoreService.getAuditStoreList(store.getBusinessId(),
                    null, null);
            if (!auditStoreList.isEmpty()) {
                auditGroupList = auditStoreList.stream()
                        .map(AuditStoreDto::map)
                        .collect(Collectors.groupingBy(auditStore -> dateFormat.format(auditStore.getCreateTime())))
                        .entrySet()
                        .stream()
                        .map(entry -> new GroupValue<>(entry.getKey(), entry.getValue()))
                        .sorted(Comparator.comparing(GroupValue::getName, Comparator.reverseOrder()))
                        .collect(Collectors.toList());
            }
        }

        /*
            获取地区名称
         */
        Map<Integer, String> regionNameMap = regionCodeService.batchGetName(regionCodeSet);

        /*
            获取商店分类
         */
        Map<Integer, String> storeClassMap = multiDictService.batchGetName(MultiDictEnum.STORE_CLASS.getValue(),
                storeClassSet, Integer::parseInt);

        StoreViewDto storeDto = StoreViewDto.map(store);
        StoreAccountViewDto storeAccountDto = StoreAccountViewDto.map(storeAccount);
        StoreBossDto storeBossDto = StoreBossDto.map(storeBoss);

        storeDto.setAddressProvinceName(regionNameMap.get(storeDto.getAddressProvince()))
                .setAddressCityName(regionNameMap.get(storeDto.getAddressCity()))
                .setAddressDistrictName(regionNameMap.get(storeDto.getAddressDistrict()))
                .setAddressStreetName(regionNameMap.get(storeDto.getAddressStreet()))
                .setMainClassName(storeClassMap.get(storeDto.getMainClass()))
                .setSubClassName(storeClassMap.get(storeDto.getSubClass()));
        storeAccountDto.setBankCityName(regionNameMap.get(storeAccountDto.getBankCity()));
        if (Objects.nonNull(preStore)) {
            preStore.setAddressProvinceName(regionNameMap.get(preStore.getAddressProvince()))
                    .setAddressCityName(regionNameMap.get(preStore.getAddressCity()))
                    .setAddressDistrictName(regionNameMap.get(preStore.getAddressDistrict()))
                    .setAddressStreetName(regionNameMap.get(preStore.getAddressStreet()))
                    .setMainClassName(storeClassMap.get(storeDto.getMainClass()))
                    .setSubClassName(storeClassMap.get(storeDto.getSubClass()));
        }
        if (Objects.nonNull(preStoreAccountDto)) {
            preStoreAccountDto.setBankCityName(regionNameMap.get(preStoreAccountDto.getBankCity()));
        }

        StoreAuditDetailDto storeAuditDetailDto = new StoreAuditDetailDto();
        storeAuditDetailDto.setStoreDto(storeDto)
                .setPreStoreDto(preStore)
                .setStoreAccountDto(storeAccountDto)
                .setPreStoreAccountDto(preStoreAccountDto)
                .setStoreBossDto(storeBossDto)
                .setPreStoreBossDto(preStoreBossDto)
                .setHistoryList(historySubmitDtoList)
                .setAuditGroupList(auditGroupList);
        return storeAuditDetailDto;
    }

    public AccountAuditDetailDto getAccountAuditDetail(Long storeId) {
        /*
            获取商店账户
         */
        List<StoreAccountEntity> storeAccountList = storeAccountService.getStoreAccountList(storeId);

        // 地区码code集合
        Set<Integer> regionCodeSet = new HashSet<>();

        List<StoreAccountViewDto> accountList = new ArrayList<>();
        StoreAccountEntity account = null;
        for (StoreAccountEntity storeAccount : storeAccountList) {
            // 收集地区码
            regionCodeSet.add(storeAccount.getBankCity());

            if (CommonEnum.ZERO.getValue().equals(storeAccount.getAuditStatus())) {
                account = storeAccount;
            } else {
                accountList.add(StoreAccountViewDto.map(storeAccount));
            }
        }
        if (Objects.isNull(account)) {
            log.info("待审核的商店账户为空");
            throw new CzzException(ResultEnum.REFRESH.getCode(), "商店没有待审核的账户");
        }

        /*
            获取地区名称
         */
        Map<Integer, String> regionNameMap = regionCodeService.batchGetName(regionCodeSet);

        for (StoreAccountViewDto storeAccountViewDto : accountList) {
            storeAccountViewDto.setBankCityName(regionNameMap.get(storeAccountViewDto.getBankCity()));
        }


        /*
            获取商店账户审核记录
         */
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        List<GroupValue<AuditStoreDto>> auditGroupList = Collections.emptyList();

        List<AuditStoreEntity> auditStoreList = auditStoreService.getAuditStoreList(null, account.getId(),
                null);
        if (!auditStoreList.isEmpty()) {
            auditGroupList = auditStoreList.stream()
                    .map(AuditStoreDto::map)
                    .collect(Collectors.groupingBy(auditStore -> dateFormat.format(auditStore.getCreateTime())))
                    .entrySet()
                    .stream()
                    .map(entry -> new GroupValue<>(entry.getKey(), entry.getValue()))
                    .sorted(Comparator.comparing(GroupValue::getName, Comparator.reverseOrder()))
                    .collect(Collectors.toList());
        }

        // 映射
        StoreAccountViewDto accountDto = StoreAccountViewDto.map(account);
        accountDto.setBankCityName(regionNameMap.get(accountDto.getBankCity()));

        // 封装返回
        AccountAuditDetailDto accountAuditDetailDto = new AccountAuditDetailDto();
        accountAuditDetailDto.setAccountList(accountList)
                .setAccount(accountDto)
                .setAuditGroupList(auditGroupList);
        return accountAuditDetailDto;
    }

    public BossAuditDetailDto getBossAuditDetail(Long storeId) {
        /*
            获取商店老板
         */
        List<StoreBossEntity> storeBossList = storeBossService.getStoreBossList(storeId);

        List<StoreBossDto> bossList = new ArrayList<>();
        StoreBossEntity boss = null;
        for (StoreBossEntity storeBoss : storeBossList) {

            if (CommonEnum.ZERO.getValue().equals(storeBoss.getAuditStatus())) {
                boss = storeBoss;
            } else {
                bossList.add(StoreBossDto.map(storeBoss));
            }
        }
        if (Objects.isNull(boss)) {
            log.info("待审核的商店老板为空");
            throw new CzzException(ResultEnum.REFRESH.getCode(), "商店没有待审核的老板");
        }


        /*
            获取商店老板审核记录
         */
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        List<GroupValue<AuditStoreDto>> auditGroupList = Collections.emptyList();

        List<AuditStoreEntity> auditStoreList = auditStoreService.getAuditStoreList(null, null,
                boss.getId());
        if (!auditStoreList.isEmpty()) {
            auditGroupList = auditStoreList.stream()
                    .map(AuditStoreDto::map)
                    .collect(Collectors.groupingBy(auditStore -> dateFormat.format(auditStore.getCreateTime())))
                    .entrySet()
                    .stream()
                    .map(entry -> new GroupValue<>(entry.getKey(), entry.getValue()))
                    .sorted(Comparator.comparing(GroupValue::getName, Comparator.reverseOrder()))
                    .collect(Collectors.toList());
        }

        // 映射
        StoreBossDto bossDto = StoreBossDto.map(boss);

        // 封装返回
        BossAuditDetailDto bossAuditDetailDto = new BossAuditDetailDto();
        bossAuditDetailDto.setBossList(bossList)
                .setBoss(bossDto)
                .setAuditGroupList(auditGroupList);
        return bossAuditDetailDto;
    }
}
